﻿using System;
using System.Runtime.Serialization;

namespace 显示器尺寸计算
{
    class Program
    {
        static void Main(string[] args)
        {

            var size = ScreenCal.Cal(34, 21, 9);
            //Console.WriteLine(size.Item1);
            //Console.WriteLine(size.Item2);
            //Console.WriteLine(size.Item3);

             size = ScreenCal.CalLImi(34, 21, 9);
            Console.WriteLine(size.Item1);
            Console.WriteLine(size.Item2);
            Console.WriteLine(size.Item3);

            //size = ScreenCal.Cal(31.5, 16, 9);
            //Console.WriteLine(size.Item1);
            //Console.WriteLine(size.Item2);
            //Console.WriteLine(size.Item3);

            //size = ScreenCal.CalLImi(31.5, 16, 9);
            //Console.WriteLine(size.Item1);
            //Console.WriteLine(size.Item2);
            //Console.WriteLine(size.Item3);


            size = ScreenCal.CalLImi(27, 16, 9);
            Console.WriteLine(size.Item1);
            Console.WriteLine(size.Item2);
            Console.WriteLine(size.Item3);

            Console.Read();
        }
    }
    // Important: This attribute is NOT inherited from Exception, and MUST be specified 
    // otherwise serialization will fail with a SerializationException stating that
    // "Type X in Assembly Y is not marked as serializable."

    [Serializable]
    public class SerializableExceptionWithoutCustomPropertiesException : Exception
    {
        public SerializableExceptionWithoutCustomPropertiesException()
        {
        }

        public SerializableExceptionWithoutCustomPropertiesException(string message)
            : base(message)
        {
        }

        public SerializableExceptionWithoutCustomPropertiesException(string message, Exception innerException)
            : base(message, innerException)
        {
        }

        // Without this constructor, deserialization will fail
        protected SerializableExceptionWithoutCustomPropertiesException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }
    }
    public class ScreenCal
    {
        /// <summary>

        /// </summary>
        /// <param name="size"> 输入 对角线长度比如 34寸</param>
        /// <param name="width">长宽比如 21:9如的21</param>
        /// <param name="height">长宽比如 21:9如的9</param>
        /// <returns>
        /// 返回三个数字，第一个长度 ，单位英寸
        /// 返回三个数字，第二个高度 ，单位英寸
        /// 返回三个数字，第一个面积 ，单位英寸平方
        /// </returns>
        public static Tuple<double, double, double> Cal(double size, int width, int height)
        {
            var a = ((width + height) * (width + height)) - 2 * (width * height);
            var x = Math.Sqrt(size * size / a);
            return new Tuple<double, double, double>(width * x, height * x, width * height * x * x);
        }

        public static Tuple<double, double, double> CalLImi(double size, int width, int height)
        {
            var a = ((width + height) * (width + height)) - 2 * (width * height);
            var x = Math.Sqrt(size * size / a);
            var guan = width * x * 2.54;
            var gao = height * x * 2.54;
            return new Tuple<double, double, double>(guan, gao, guan * gao);
        }
    }
}
